<template>
  <!-- 通知通告查看页面 -->
  <div>
    <!-- 搜索 -->
    <TopFilter :list="topFilterInit" :cols="3" labelWidth="90" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
      columnsRef="notificationDLR_view_index_01"
    ></FilterTable>

    <!-- 详情窗口 -->
    <Drawer :visible.sync="visibleDrawer" title="通知通告查看" :width="920" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <info-modal v-model="initData" @close="infoClose" />
    </Drawer>
  </div>
</template>

<script>
import { pageNotificationFeedback } from '@/api/cms-api/notificationDLR/view/index';
import { dictionary } from '@/utils/dictMixin';
import infoModal from './info';

export default {
  mixins: [dictionary],
  components: {
    infoModal
  },
  data() {
    return {
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchApi: pageNotificationFeedback,
      fetchParams: { statuss: '15631001,15631002' },
      visibleDrawer: false,
      initData: {}
    };
  },
  methods: {
    topFilterInitFun() {
      return [
        { type: 'SELECT', label: '类别', fieldName: 'notificationType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1561') },
        { type: 'INPUT', label: '主题', fieldName: 'notificationTitle', placeholder: '请输入', initialValue: '' },
        { type: 'RANGE_DATE', label: '发布时间', fieldName: 'publisDate', valueFormat: 'yyyy-MM-dd', placeholder: '请选择' },
        { type: 'SELECT', label: '紧急程度', fieldName: 'urgency', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1562') },
        // { type: 'MULTIPLE_SELECT', label: '阅读状态', fieldName: 'statusList', placeholder: '请选择', initialValue: [], itemList: this.createDictList('1564') }
        { type: 'SELECT', label: '阅读状态', fieldName: 'status', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1563') }
      ];
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row, 'show')}>
                  详情
                </el-button>
              </div>
            );
          }
        },
        {
          title: '类别',
          dataIndex: 'notificationType',
          sorter: true,
          filterItems: this.createDictList('1561'),
          render: props => {
            return <span>{this.createDictText(props.row.notificationType, '1561')}</span>;
          }
        },
        {
          title: '主题',
          dataIndex: 'notificationTitle',
          width: 100,
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row, 'show')}>
                  {props.row.notificationTitle}
                </el-button>
              </div>
            );
          }
        },
        { title: '编号', dataIndex: 'notificationNo', sorter: true },
        {
          title: '紧急程度',
          dataIndex: 'urgency',
          sorter: true,
          filterItems: this.createDictList('1562'),
          render: props => {
            return (
              <span>
                {props.row.urgency === 15621001 ? (
                  <span style="color:red">
                    {this.createDictText(props.row.urgency, '1562')}
                    <i class="el-icon-s-flag"></i>
                  </span>
                ) : (
                  <span>{this.createDictText(props.row.urgency, '1562')}</span>
                )}
              </span>
            );
          }
        },
        { title: '发起部门', dataIndex: 'publishOrgName', sorter: true },
        { title: '发布人', dataIndex: 'publishPersonName', sorter: true },
        {
          title: '阅读状态',
          dataIndex: 'status',
          sorter: true,
          filterItems: this.createDictList('1563'),
          render: props => {
            return <span>{this.createDictText(props.row.status, '1563')}</span>;
          }
        },
        { title: '有效期至', dataIndex: 'endTime', sorter: true, dateFormat: 'yyyy-MM-dd' },
        { title: '发布时间', dataIndex: 'publishDate', dateFormat: 'yyyy-MM-dd HH:mm', sorter: true },
        { title: '首次已读时间', dataIndex: 'feedback_time', dateFormat: 'yyyy-MM-dd HH:mm', sorter: true }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      //   if(val.statusList.length != 0){
      if (!val.status) {
        // val.statuss = val.statusList.join(',');
        val.statuss = '15631001,15631002';
      } else {
        val.statuss = '';
      }

      this.fetchParams = Object.assign({}, val);
      this.fetchParams.publisStartDate = this.fetchParams.publisDate[0];
      this.fetchParams.publisEndDate = this.fetchParams.publisDate[1];
      console.log('搜索框数据：', this.fetchParams);
    },
    //展开收起时触发
    collapseHandle() {},
    editHandle(row, type) {
      if (row.publisStatus === 15631003) {
        this.$message({
          type: 'error',
          message: '当前通过已经撤回，暂时无法查看详情！'
        });
        return;
      }
      this.initData = {
        type: type, // add-edit-show
        notificationId: row.notificationId,
        id: 1001
      }; //行id
      this.visibleDrawer = true;
    },
    //关闭详情 rData 是页面关闭回调回来的数据
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped>
.el-icon-s-flag {
  color: red;
  margin-left: 5px;
}
</style>
